//
//  NoticeDetailController.m
//  智慧小区
//
//  Created by lab603 on 15/7/7.
//  Copyright (c) 2015年 Dreamsoul. All rights reserved.
//

#import "NoticeDetailController.h"
#import "Notice.h"
#define Top_Padding 10
#define Left_Padding 20
@interface NoticeDetailController ()
//背景
@property (nonatomic,weak)UIImageView *backgroundView;
//标题
@property (nonatomic,weak)UILabel *titleLabel;
//详情
@property (nonatomic,weak)UILabel *detailLabel;
//物业管理
@property (nonatomic,weak)UILabel *propertyLabel;
//时间
@property (nonatomic,weak)UILabel *timeLabel;
@end

@implementation NoticeDetailController
- (id)init{
    self = [super init];
    if (self) {
        self.title = @"通知详情";
        self.view.backgroundColor = APP_BACK_COLOR;
        [self initSubViews];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //避免在ios7后出现导航栏遮挡视图
    if (iOS7) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    //[self initSubViews];
}
/**
 *  初始化子控件
 */
- (void)initSubViews{
    //背景
    UIImageView *backgroundView = [[UIImageView alloc] init];
    backgroundView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backgroundView];
    self.backgroundView = backgroundView;
    //titleLabel
    //标题label
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:15.0];
    [self.view addSubview:titleLabel];
    _titleLabel = titleLabel;
    //通知详情
    UILabel *detailLabel = [[UILabel alloc] init];
    detailLabel.textColor = [UIColor grayColor];
    detailLabel.backgroundColor = [UIColor clearColor];
    detailLabel.font = [UIFont systemFontOfSize:14.0];
    detailLabel.numberOfLines = 0;
    [self.view addSubview:detailLabel];
    _detailLabel = detailLabel;
    //物业管理
    UILabel *propertyLabel = [[UILabel alloc] init];
    propertyLabel.textColor = [UIColor grayColor];
    propertyLabel.backgroundColor = [UIColor clearColor];
    propertyLabel.font = [UIFont systemFontOfSize:13.0];
    [self.view addSubview:propertyLabel];
    _propertyLabel = propertyLabel;
    //时间
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.textColor = [UIColor grayColor];
    timeLabel.backgroundColor = [UIColor clearColor];
    timeLabel.font = [UIFont systemFontOfSize:13.0];
    [self.view addSubview:timeLabel];
    _timeLabel = timeLabel;
    [self setSubViews];
}
/**
 *  给子控件设置Frame和值
 */
- (void)setSubViews{
    //背景图片
    CGFloat backgroundViewX = 0;
    CGFloat backgroundViewY = 0;
    CGFloat backgroundViewW = ScreenWidth;
    //背景高度待定
    CGFloat backgroundViewH = 0;
    //标题
    CGFloat titleLabelX = Top_Padding;
    CGFloat titlelabelY = Left_Padding;
    CGSize titleLabelSize = [self.notice.title sizeWithFont:[UIFont systemFontOfSize:15.0]];
    _titleLabel.frame = (CGRect){{titleLabelX,titlelabelY},titleLabelSize};
    //详情
    CGFloat detailLabelX = titleLabelX;
    CGFloat detailLabelY = CGRectGetMaxY(_titleLabel.frame)+Left_Padding;
    CGSize detailLabelSize = [self.notice.detail sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:(CGSize){ScreenWidth - 2*Top_Padding,MAXFLOAT}];
    _detailLabel.frame = (CGRect){{detailLabelX,detailLabelY},detailLabelSize};
    //物业管理
    CGFloat propertyLabelX = detailLabelX;
    CGFloat propertyLabelY = CGRectGetMaxY(_detailLabel.frame)+Left_Padding;
    CGSize propertyLabelSize = [@"物业管理" sizeWithFont:[UIFont systemFontOfSize:13.0]];
    _propertyLabel.frame = (CGRect){{propertyLabelX,propertyLabelY},propertyLabelSize};
    //时间Label
    CGFloat timeLabelX = propertyLabelX;
    CGFloat timeLabelY = CGRectGetMaxY(_propertyLabel.frame)+Top_Padding;
    CGSize timeLabelSize = [self.notice.time sizeWithFont:[UIFont systemFontOfSize:13.0]];
    _timeLabel.frame = (CGRect){{timeLabelX,timeLabelY},timeLabelSize};
    backgroundViewH = CGRectGetMaxY(_timeLabel.frame) + Left_Padding;
    _backgroundView.frame = CGRectMake(backgroundViewX, backgroundViewY, backgroundViewW, backgroundViewH);
    
    //赋值
    self.titleLabel.text = self.notice.title;
    self.detailLabel.text = self.notice.detail;
    self.propertyLabel.text = @"物业管理";
    self.timeLabel.text = self.notice.time;
}
- (void)setNotice:(Notice *)notice{
    _notice = notice;
    [self setSubViews];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
